package com.sanhe.rfmuscle.activity.work;

import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;

import androidx.annotation.Nullable;

import com.menu.app.MyApp;
import com.menu.app.util.Constant;
import com.sanhe.rfmuscle.App;
import com.sanhe.rfmuscle.R;
import com.sanhe.rfmuscle.databinding.ActivitySettingBinding;
import com.sanhe.rfmuscle.util.Const;

public class SettingActivity extends BaseWorkActivity {
    Typeface medium = Typeface.createFromAsset(App.getApp().getAssets(), "HarmonyOS_Sans_Medium.ttf");
    ActivitySettingBinding binding;

    String from;

    public void setFrom(String str) {
        from = str;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivitySettingBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        binding.back.setOnClickListener(v -> {
            dealBack();
            if (Const.jump) {
                finish();
            }
        });
        binding.temp.setOnClickListener(v -> sendTouchEvent((byte) 1, (byte) 0x41));
        binding.flow.setOnClickListener(v -> sendTouchEvent((byte) 1, (byte) 0x42));
        binding.vref.setOnClickListener(v -> sendTouchEvent((byte) 1, (byte) 0x43));
        binding.rent.setOnClickListener(v -> sendTouchEvent((byte) 1, (byte) 0x1a));
        binding.rf.setOnClickListener(v -> sendTouchEvent((byte) 1, (byte) 0x1d));
        binding.sn.setOnClickListener(v -> {
            Intent intent = new Intent(this, Pwd2Activity.class);
            startActivity(intent);
        });
        binding.temp.setTypeface(medium);
        binding.flow.setTypeface(medium);
        binding.vref.setTypeface(medium);
        binding.rent.setTypeface(medium);
        binding.rf.setTypeface(medium);
        binding.sn.setTypeface(medium);

        binding.temp.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    binding.tempBg.setImageResource(R.mipmap.shade_bg_press3);
                } else if (event.getAction() == MotionEvent.ACTION_UP) {
                    binding.tempBg.setImageResource(R.mipmap.shade_bg3);
                }
                return false;
            }
        });
        binding.flow.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    binding.flowBg.setImageResource(R.mipmap.shade_bg_press3);
                } else if (event.getAction() == MotionEvent.ACTION_UP) {
                    binding.flowBg.setImageResource(R.mipmap.shade_bg3);
                }
                return false;
            }
        });

        binding.vref.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    binding.vrefBg.setImageResource(R.mipmap.shade_bg_press3);
                } else if (event.getAction() == MotionEvent.ACTION_UP) {
                    binding.vrefBg.setImageResource(R.mipmap.shade_bg3);
                }
                return false;
            }
        });

        binding.rent.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    binding.rentBg.setImageResource(R.mipmap.shade_bg_press3);
                } else if (event.getAction() == MotionEvent.ACTION_UP) {
                    binding.rentBg.setImageResource(R.mipmap.shade_bg3);
                }
                return false;
            }
        });

        binding.rf.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    binding.rfBg.setImageResource(R.mipmap.shade_bg_press3);
                } else if (event.getAction() == MotionEvent.ACTION_UP) {
                    binding.rfBg.setImageResource(R.mipmap.shade_bg3);
                }
                return false;
            }
        });

        binding.sn.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    binding.snBg.setImageResource(R.mipmap.shade_bg_press3);
                } else if (event.getAction() == MotionEvent.ACTION_UP) {
                    binding.snBg.setImageResource(R.mipmap.shade_bg3);
                }
                return false;
            }
        });
        try {
            binding.ver.setText("-V." + Const.ver);
        } catch (Exception e) {
            Log.e(TAG, "onCreate: version err");
        }
    }

    protected void dealBack() {
        MyApp.getApp().setIgnore(true);
        sendTouchEvent((byte) 0, (byte) (0x20));
        finish();
    }

    public boolean fromPwd2() {
        Class c = Pwd2Activity.class;
        if (c == null) {
            return false;
        }
        return c.getSimpleName().equals(from);
    }

}
